# -*- coding = utf-8 -*-
# @Time    : 2025/3/15 上午10:29
# @Author  : yqk
# @File    : testSqlite.py
# @Software: PyCharm

import sqlite3

# 连接到 SQLite 数据库（如果文件不存在，会自动创建）
conn = sqlite3.connect('test.db')
print("Opened database successfully")

# 创建游标对象
c = conn.cursor()

# 创建表
# sql = '''
#     create table company
#     (id int primary key not null,
#     name text not null,
#     age int not null,
#     address char(50),
#     salary real);
# '''

# 插入数据
# sql = '''
#     insert into company (id, name, age, address, salary)
#     values (1, '张三', 32, '北京', 8000);
# '''
# sql1 = '''
#     insert into company (id, name, age, address, salary)
#     values (2, '李四', 32, '上海', 8000);
# '''

#查找数据
sql = '''
    select * from company;
'''
cur = c.execute(sql)
for row in cur:
    print(row)

# # 执行 SQL 语句
# c.execute(sql)
# c.execute(sql1)

# 提交事务
conn.commit()

# 关闭连接
conn.close()
